USE [influenza]
GO

/****** Object:  StoredProcedure [dbo].[SP_RptIndxRechazo]    Script Date: 03/23/2010 12:17:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[SP_RptIndxRechazo]
@param varchar(100)

as
Begin
declare 
@qry1 varchar(8000)

set @qry1='declare
@rechazoT float,
@totalR float,
@Totalf float

select @rechazoT= COUNT(nRechazo) from dat_laboratorio 
where nRechazo is not NULL and nRechazo=0 and nTecnica is NULL and nResultado is NULL'
if @param>0
  begin
     set @qry1=@qry1+' and id_laboratorio='+@param+';'
  end

set @qry1=@qry1+' select @totalR= count(id_principal) from dat_laboratorio'
if @param>0
  begin
     set @qry1=@qry1+' where id_laboratorio='+@param+';'
  end
set @qry1=@qry1+' select @rechazoT as Rechazo,@totalR as TotalRegistros,((@rechazoT/case  when @totalR=0 then 1 else  @totalR end)*100) as Porcentaje'

 exec(@qry1)
End
GO

